/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.lucava.boatskeeper.server.dao;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.lucava.boatskeeper.shared.dto.BoatDto;

/**
 *
 * @author glenn
 */
public class MockBoatDao {

    final static Map<Integer, BoatDto> boats = new HashMap<Integer, BoatDto>();

    static {
        for (int i = 0; i < 10; i++) {
            BoatDto b = new BoatDto();
            b.setId(i);
            b.setName(" boat " + i);
            b.getCategory().setId(i);
            b.getCategory().setName("aCat-" + i);
            b.setLatitude((float) (48.383 + (i* 0.5)));
            b.setLongitude((float) -4.5);
            boats.put(i, b);
        }
    }

    public static void add(BoatDto b) {
        b.setId(boats.size());
        b.getCategory().setName(MockCategoryDao.get(b.getCategory().getId()).getName());

        boats.put(b.getId(), b);
    }

    public static void save(BoatDto b) {
        boats.get(b.getId()).setName(b.getName());
        boats.get(b.getId()).getCategory().setName(MockCategoryDao.get(b.getCategory().getId()).getName());
        boats.get(b.getId()).getCategory().setId(b.getCategory().getId());
        boats.get(b.getId()).setBoatImage(b.getBoatImage());
    }

    public static void delete(BoatDto b) {

        boats.remove(b.getId());
    }

    public static BoatDto get(Integer id) {
        return boats.get(id);
    }

    public static List<BoatDto> getAll() {

        return new ArrayList<BoatDto>(boats.values());
    }
}
